#!/usr/bin/env python3
# -*- coding: utf-8 -*-


from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

url = r'https://www.zhihu.com'

options = webdriver.ChromeOptions()
if False:
    options.headless = True

options.add_argument('user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36')
driver = webdriver.Chrome(chrome_options=options)

driver.get(url)

cookies = driver.get_cookies()
# for c in cookies:
#     driver.add_cookie(c)

wait = WebDriverWait(driver, 5)
a = wait.until(expected_conditions.text_to_be_present_in_element((By.XPATH, '//*[@id="root"]/div/main/div/div/div/div[2]/div[2]/span'), '登录'))
login = driver.find_element_by_xpath('//*[@id="root"]/div/main/div/div/div/div[2]/div[2]/span')
login.click()

username = driver.find_element_by_name('username')
password = driver.find_element_by_name('password')
username.send_keys('13575464594')
password.send_keys('19860705')

button = driver.find_element_by_xpath('//*[@id="root"]/div/main/div/div/div/div[2]/div[1]/form/button')
button.click()